package com.fhz.module_main.adapter

import android.content.Context
import android.view.LayoutInflater
import android.view.ViewGroup
import androidx.recyclerview.widget.RecyclerView
import com.bumptech.glide.Glide
import com.chad.library.adapter.base.BaseQuickAdapter
import com.fhz.module_main.databinding.HomeItemFollowCardViewBinding
import com.fhz.module_main.entity.RecommendEntity

/**
 * 时间:2023/5/10
 * @author Mr.Feng
 * 简述: 推荐中的rv的banner ,多布局中的一部分
 */
class RecycleSelectAdapter : BaseQuickAdapter<RecommendEntity.ItemX, RecycleSelectAdapter.VH>() {

    // 自定义ViewHolder类
    class VH(
        parent: ViewGroup,
        val binding: HomeItemFollowCardViewBinding = HomeItemFollowCardViewBinding.inflate(
            LayoutInflater.from(parent.context), parent, false
        ),
    ) : RecyclerView.ViewHolder(binding.root)

    override fun onCreateViewHolder(context: Context, parent: ViewGroup, viewType: Int): VH {
        // 返回一个 ViewHolder
        return VH(parent)
    }

    override fun onBindViewHolder(holder: VH, position: Int, item: RecommendEntity.ItemX?) {
        // 设置item数据
        println(11111)
//        println(item?.itemList?.get(0)?.data?.itemList?.get(0)?.data?.content?.data?.title)
//        println(item?.data?.author?.icon)
//        item?.let {
//            println(it.data.header.icon)
//        }
        if (item != null) {
            println(item.data.content.data.title)
        }
        if (item != null) {
            holder.binding.tvTitle.text = item.data.content.data.title
//            holder.binding.tvDescription.text = item.data.content.data.description
            holder.binding.tvDescription.text = item.data.content.data.category
            Glide.with(context).load(item.data.content.data.cover.feed).into(holder.binding.ivVideoCover)
            Glide.with(context).load(item.data.header.icon).into(holder.binding.ivAuthor)
        }


    }

}